package com.henrybit.servlet;

import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;

import org.apache.log4j.Logger;

import com.henrybit.exception.LogException;
import com.henrybit.util.DBFactory;
import com.henrybit.util.LogFactory;

/**
 * Servlet implementation class InitServlet<p>
 * 系统初始化<p>
 * @author henrybit
 * @version 1.0
 */
public class InitServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
	
	public void init(ServletConfig servletConfig) {
		try {
			super.init(servletConfig);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
        String root = getServletContext().getRealPath("/");
        
        //初始化log4j
        String logConfig = root + servletConfig.getInitParameter("log4j");
        try {
			LogFactory.init(logConfig);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
        
        //初始化DB
		try {
			DBFactory.init();
		} catch (Exception e) {
			//log4j
		}
	}
}
